package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.user.UserDetailInfo;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.Request;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

import java.util.Map;

/**
 * Created by luo_guangwen on 2017/8/13.
 */

public class GetUserDetailInfoRequest extends Request<UserDetailInfo> {

    public GetUserDetailInfoRequest(Response.Listener<UserDetailInfo> listener) {
        super(Method.GET, UrlUtils.createUrl("/appapi/user_center"), listener);
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        addParam("efairyuser_id", CacheManager.getUserId());
        addParam("access_token", CacheManager.getAccessToken());
        return super.getParams();
    }

    @Override
    protected UserDetailInfo parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<UserDetailInfo>() {
        }.getType());
    }

}
